package com.gitee.loyo.impl;

import io.vertx.core.Handler;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.streams.ReadStream;


public class DelegateReadStream implements ReadStream<Buffer> {
    final ReadStream<Buffer> delegate;
    final Handler<Buffer> delegateHandler;

    public DelegateReadStream(ReadStream<Buffer> delegate, Handler<Buffer> delegateHandler) {
        this.delegate = delegate;
        this.delegateHandler = delegateHandler;
    }

    @Override
    public ReadStream<Buffer> exceptionHandler(Handler<Throwable> handler) {
        return delegate.exceptionHandler(handler);
    }

    @Override
    public ReadStream<Buffer> handler(Handler<Buffer> handler) {
        return delegate.handler(buffer -> {
            delegateHandler.handle(buffer);
            handler.handle(buffer);
        });
    }

    @Override
    public ReadStream<Buffer> pause() {
        return delegate.pause();
    }

    @Override
    public ReadStream<Buffer> resume() {
        return delegate.resume();
    }

    @Override
    public ReadStream<Buffer> fetch(long amount) {
        return delegate.fetch(amount);
    }

    @Override
    public ReadStream<Buffer> endHandler(Handler<Void> endHandler) {
        return delegate.endHandler(endHandler);
    }
}
